package com.olymtech.jbricks.dingtalk.message.delivery.msg;

import com.dingtalk.api.request.OapiChatSendRequest;
import com.olymtech.jbricks.dingtalk.message.LinkMessage;
import com.olymtech.jbricks.dingtalk.message.Message;
import com.olymtech.jbricks.dingtalk.message.TextMessage;
import com.taobao.api.TaobaoObject;

/**
 * @author haoting.wang
 * @date 2020/12/10 2:36 下午
 **/
public class ChatMessageService {

    public static TaobaoObject convertText(Message message) {

        TextMessage textMessage = (TextMessage) message;

        OapiChatSendRequest.Msg msg = new OapiChatSendRequest.Msg();
        OapiChatSendRequest.Text text = new OapiChatSendRequest.Text();
        text.setContent(textMessage.content);
        msg.setText(text);
        msg.setMsgtype(textMessage.type().getType());
        return msg;

    }

    public static TaobaoObject convertLink(Message message) {

        LinkMessage linkMessage = (LinkMessage) message;
        // link消息
        OapiChatSendRequest.Msg msg = new OapiChatSendRequest.Msg();
        OapiChatSendRequest.Link link = new OapiChatSendRequest.Link();
        link.setMessageUrl(linkMessage.messageUrl);
        link.setPicUrl(linkMessage.picUrl);
        link.setText(linkMessage.text);
        link.setTitle(linkMessage.title);

        msg.setMsgtype(linkMessage.type().getType());
        msg.setLink(link);
        return msg;
    }

}